package com.ckd.flyingtrip.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RadioButton;

import com.ckd.flyingtrip.R;
import com.ckd.flyingtrip.activity.BaseActivity;

public class Wallet_YouhuijuanAdapter extends BaseAdapter {

    private BaseActivity context;
    private Onc_battery close_battery;
    private int checked = -1;//初始选择为-1，position没有-1嘛，那就是谁都不选咯
    public interface Onc_battery{
        public void click(View v,int posin);
    }
    public Wallet_YouhuijuanAdapter(BaseActivity context, Onc_battery close_battery){
        this.context = context;
        this.close_battery = close_battery;
    }
    public void setChecked(int checked) {//设定一个选中的标志位，在activity中传入值。
        this.checked = checked;
    }
    @Override
    public int getCount() {
//        if (Tools.isEmpeyNull(list)) {
//            return list.size();
//        }
        return 10;
    }

    @Override
    public Object getItem(int i) {
//        return list.get(i);
        return i;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {
        final ViewHolder holder;
        View view = null;
        if (convertView == null) {
            view = View.inflate(context, R.layout.item_youhuijuan, null);
            holder = new ViewHolder();
            view.setTag(holder);
            holder.radio =  view.findViewById(R.id.radio);
        } else {
            view = convertView;
            holder = (ViewHolder) convertView.getTag();
        }
        if (checked == position) {
            holder.radio.setChecked(true);
        }else {
            holder.radio.setChecked(false);
        }
        holder.radio.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                close_battery.click(view,position);
            }
        });
        return view;
    }

    public static final class ViewHolder {
        RadioButton radio;

    }
}